/*
 * cluster.h
 *
 *  Created on: Mar 1, 2011
 *      Author: Mo
 */
#pragma once

#include "pixel.h"
#include <vector>

/**
 * This class stores all the connected pixels of a binary image as a cluster of pixels.
 */
class Cluster
{
private:
	int size;				//!< Number of pixels in the cluster.
	int value;				//!< The value of the pixels in the cluster (usually 1).
	std::vector<Pixel> pixels;	//!< The vector of pixels in the cluster.

public:
	Cluster();				//!< Default constructor. Creates an empty cluster with value=-1
	//Cluster(Cluster& other);//!< Copy constructor
	Cluster(int**, int);	//!< Constructor, converts a list of pixels stored in a n-by-2 array to a Cluster object with the given value
	Cluster(int[][2], int);//!< Constructor, converts a list of pixels stored in a n-by-2 array to a Cluster object with the given value
	~Cluster();				//!< Destructor
	int getSize(void);		//!< Returns the number of pixels in the cluster
	void setSize(int);		//!< Sets the size to the provided parameter. used for clear(), in which size needs to be reset to zero.
	int getValue(void);	//!< Returns the value of the pixels in the cluster (usually 1).
	Cluster& operator= (const Cluster&); //!< Overloading the assignment operator.

	/**
	 * Tells if the calling cluster includes the pixel in the specified coordinate.
	 * \param row,col The coordinate of the given pixel
	 * \returns true if the cluster has a pixel in that coordinate, false otherwise.
	 */
	bool includes (int row, int col);

	/**
	 * Tells if the calling cluster includes a pixel matching the specified pixel.
	 * \param pixel The pixel that we are querying the cluster for
	 * \returns true if the calling cluster includes a matching pixel, false otherwise.
	 */
	bool includes (Pixel pixel);

	/**
	 * Returns the ith pixel in the cluster.
	 * \param index The index of the pixel to be returned
	 * \return The pixel in that index in the cluster's pixel vector.
	 */
	Pixel element(int index);

	void refreshSize(void);		//!< Calculates the number of pixels in the cluster, assigns it to the size class variable.
	void refreshValue(void);	//!< Updates or initializes the value class variable.
	void add(Pixel pixel);		//!< Adds a pixel to the pixel vector in the cluster.
	void clear (void); 			//!< Empties the pixels vector and resets the size to zero.

	/**
	 * Creates a Pixel on the fly with provided coordinate and value, and adds it to the
	 * pixel vector.
	 * \param row,col The coordinate of the pixel to be added to the pixel vector.
	 * \param value The value of the pixel to be added to the pixel vector.
	 */
	void add(int row, int col, int value);

	/**
	 * Creates a Pixel on the fly with provided coordinate and the default cluster's value,
	 * and adds it to the pixel vector.
	 * \param row,col The coordinate of the pixel to be added to the pixel vector.
	 */
	void add(int row, int col);
};
